home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / 107_01.zip / CTRIG.C < prev    next >
C/C++ Source or Header  |  1993-06-06  |  3KB  |  104 lines

  1.  
  2.  
  3.  /*  **** CTRIG.C *****
  4. A group of programs in C, using the BDS-C floating point package,
  5. as modified by L. C. Calhoun called FLOATXT, which compute some
  6. commonly used transcendental functions - to wit*
  7.     sine, cosine, tangent and arctangent
  8.     convert degrees to radians, convert radians to degrees
  9. These functions are discussed in detail in CTRIG.DOC
  10.  
  11. L. C. Calhoun
  12. 257 South Broadway
  13. Lebanon, Ohio 45036   513 932 4541/433 7510
  14.  
  15.  *** revision 13 July 1981 to 1) refine precision of constants,
  16.  especially pi related values  2) to utilize string constants
  17.  as pseudo static numeric constants.  THIS WILL ONLY WORK WITH
  18.  BDS C V 1.44 (and hopefully later).
  19.  3) to add ARCTAN2() function to identify quadrant
  20.  
  21.   */
  22.  
  23. /* simple ones first converting degrees - radians */
  24.  
  25. char *degtorad(rad,deg) /*obvious arguments in 5 char fp */
  26. char *rad, *deg;
  27. {
  28.     char *fpmult(),*radindeg;
  29.     radindeg = "\71\36\175\107\373";
  30.     fpmult(rad,deg,radindeg);
  31.     return (rad);
  32. }
  33.  
  34. char *radtodeg(deg,rad) /* 5 char fp arguments */
  35. char *deg, *rad;
  36. {
  37.     char *fpmult(), *deginrad;
  38.     deginrad = "\12\162\227\162\6";
  39.     fpmult(deg,rad,deginrad);
  40.     return (deg);
  41. }
  42.  
  43. /* service function sinev which evaluates when range of angle
  44. reduced to plus or minus pi/2 (90 deg) */
  45.  
  46. char *sinev(result,angle)
  47.  
  48. char *result, angle[5];
  49. {
  50.     char *fpmult(),x[5],xsq[5];
  51.     char *coef[5],termreslt[5];
  52.     char *fpadd(),*fpasg();
  53.     int index;
  54.  
  55.     /*  use the exponent part of the floating point
  56.         to check for threat of underflow  use small
  57.         angle approximation if appropriate  */
  58.     if ( (angle[4] > 128) && (angle[4] < 226) )
  59.        {fpasg(result,angle);       return (result);
  60.       }   /* solution to fpmult underflow problem */
  61.  
  62. /* series coef are 1., -.1666666, .008333026, -.0001980742,
  63.     .000002601887  determined from coefset program */
  64.     coef[0] = "\0\0\0\100\1";
  65.     coef[1] = "\157\252\252\252\376";
  66.     coef[2] = "\271\242\103\104\372";
  67.     coef[3] = "\320\352\46\230\364";
  68.     coef[4] = "\246\15\116\127\356";
  69.     fpasg(x,angle);
  70.     fpmult(xsq,x,x);
  71.     setmem(result,5,0);
  72.  /* to this point the coef have been initialized, the angle
  73.     copied to x, x squared computed, and the result initialized */
  74.  
  75. /* now to do the polynomial approximation */
  76.     index = 0;
  77.     while ( (index <= 4) && ( (x[4] > 194) || (x[4] < 64) ) )
  78.     /* use index for loop, and exponent of x to avoid underflow
  79.        problems */
  80.     {fpmult(termreslt,coef[index],x);
  81.     fpadd(result,result,termreslt);
  82.      index++;
  83.      fpmult(x,x,xsq);
  84.     }
  85.     return (result);
  86. }
  87.  
  88.  /* here is sine(result,angle) with angle in radians */
  89.  
  90. char *sine(result,angle)
  91.  
  92. char *result, *angle;
  93. {
  94.     char *fpmult(),*twopi,*halfpi;
  95.     char *mtwopi,*mhalfpi,*fpasg(),*fpchs();
  96.     char *pi,*sinev(),*fpadd();
  97.     char y[5],*fpsub();
  98.     int fpcomp(), compar;
  99.     int signsine;
  100.  /* some initialization required here */
  101.     signsine = 1;
  102.     twopi    = "\171\356\207\144\3";
  103.     halfpi    = "\171\356\207\144\1";
  104.     pi    = "\171